package org.iks.common.aop.handler;

import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;
import org.iks.common.enums.ChatMessageType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Author kzou
 * Date 2024/3/23
 * Description: mybatis 自定义类型处理器
 *
 * @see ChatMessageType
 */
public class ChatMessageTypeTypeHandler implements TypeHandler<ChatMessageType> {

    @Override
    public void setParameter(PreparedStatement ps, int i, ChatMessageType parameter, JdbcType jdbcType) throws SQLException {
        ps.setInt(i, parameter.getCode());
    }

    @Override
    public ChatMessageType getResult(ResultSet rs, String columnName) throws SQLException {
        return ChatMessageType.of(rs.getInt(columnName));
    }

    @Override
    public ChatMessageType getResult(ResultSet rs, int columnIndex) throws SQLException {
        return ChatMessageType.of(rs.getInt(columnIndex));
    }

    @Override
    public ChatMessageType getResult(CallableStatement cs, int columnIndex) throws SQLException {
        return ChatMessageType.of(cs.getInt(columnIndex));
    }

}
